<?php
header('Content-Type:text/html;charset=utf-8');
header('Access-Control-Allow-Origin:http://127.0.0.1:5500');

$servername = "localhost:3306";
$username ='root';
$password ='root';
$dbname='1907';
 
// 创建连接
$conn =mysqli_connect($servername, $username, $password,$dbname);
 
// 检测连接
if (!$conn) {
    //连接失败
    die("连接失败");
} 
// echo "连接成功";

$sql = 'select *  from userinfo';

$result = mysqli_query($conn,$sql);
$arr=array();
while($data=mysqli_fetch_array($result)){

    $obj=array();
    $obj["username"]=$data["username"];
    $obj["id"]=$data["id"];
    $obj["password"]=$data["password"];
    $obj["telephone"]=$data["telephone"];
    $arr[]=$obj;
}

echo json_encode($arr);

?>